package ch09;

import java.sql.Connection;

import javax.naming.InitialContext;
import javax.sql.DataSource;

public class JDBCFactory {	
	private static DataSource ds;	

	static {
		try {
			InitialContext ctx = new InitialContext();
			ds = (DataSource) ctx.lookup("java:comp/env/jdbc/jspDB");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		Connection conn = null;
		try {			
			conn = ds.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
}